package com.amado.course35Concurrent;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;

/**
 * HashMap,HashTable hashTable不允许null值与null键
 * 
 * @author Administrator
 *
 */
public class S02HashMapHashTable {

	public static void main(String[] args) {
		CountDownLatch startSignal = new CountDownLatch(1);
		Map<String, String> hashMap = new HashMap<>();
		Map<String, String> hashTable = new Hashtable<>();
		System.out.println("sadf");
		for (int i = 0; i < 500; i++) {
			// ac1 ac2
			new Thread(new Runnable() {

				@Override
				public void run() {
					try {
						startSignal.await();
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					for (int j = 0; j < 100; j++) {
						hashMap.put(UUID.randomUUID().toString(), "1");
					}
				}
			}).start();
			new Thread(new Runnable() {

				@Override
				public void run() {
					try {
						startSignal.await();
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					for (int j = 0; j < 100; j++) {
						hashTable.put(UUID.randomUUID().toString(), "1");
					}
				}
			}).start();

		}
		startSignal.countDown();
		try {
			System.out.println("--");
			Thread.sleep(4000);
			System.out.println("--33");
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("hashMap =" + hashMap.size());
		System.out.println("hashTable =" + hashTable.size());
//		Map<String, String> hashTable = new Hashtable<>();
//		// ac1 ac2
//		hashTable.put(UUID.randomUUID().toString(), 1);
	}

}